package xworker.swt.dataObject.bind.values;

import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.dataObject.DataObject;
import xworker.swt.dataObject.bind.Value;
import xworker.lang.util.UtilData;

public class Not implements Value {
    Thing thing;

    public Not(Thing thing){
        this.thing = thing;
    }

    @Override
    public Object getValue(Object value, DataObject dataObject, ActionContext actionContext) {
        String attributeName = thing.doAction("getAttributeName", actionContext);
        if(attributeName != null && !attributeName.isEmpty()){
            return !dataObject.getBoolean(attributeName);
        }else {
            return !UtilData.isTrue(value);
        }
    }

    public static Not create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        return new Not(self);
    }
}
